package band.wukong.practice.springboot.boot.da.jpa;

import band.wukong.practice.springboot.boot.da.entity.Musican;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author wukong(wukonggg@139.com)
 */
@Service
public class MusicanService {

    @Autowired
    MusicanRepositoryJpaImpl repo;

    @Transactional(rollbackFor = {IllegalArgumentException.class})
    public Musican saveMusicanWithRollBack(Musican m) {
        Musican musican = repo.save(m);

        // 当然，这样不好。。。这只是个例子。。。
        if (m.getName().equals("万碎万碎万万碎")) {
            throw new IllegalArgumentException("BIU...你死了...数据回滚...");
        }

        return musican;
    }

    @Transactional(noRollbackFor = {IllegalArgumentException.class})
    public Musican saveMusicanWithoutRollBack(Musican m) {
        Musican musican = repo.save(m);

        // 当然，这样不好。。。这只是个例子。。。
        if (m.getName().equals("万碎万碎万万碎")) {
            throw new IllegalArgumentException("BIU...没打着...数据不会回滚...");
        }

        return musican;
    }



}
